package jason.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jason.entities.JsonData;
import com.jason.entities.Payment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RateLimitController
{
    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandler = "handleException")
    public JsonData byResource()
    {
        return new JsonData(200,"按资源名称限流测试OK",new Payment(2020L,"serial001"));
    }
    public JsonData handleException(BlockException exception)
    {
        return new JsonData(444,exception.getClass().getCanonicalName()+"\t 服务不可用",null);
    }
}
